<?php
/**
 * Created by PhpStorm.
 * User: rocky
 * Date: 2022-05-24
 * Time: 21:52
 */

namespace ExAdmin\ui\component\echart;

/**
 * 地图
 * Class MapChart
 * @package ExAdmin\ui\component\echart
 */
class MapChart extends Echart
{
   

    protected $data = [];

    public function __construct()
    {
        parent::__construct();
      
        $this->options([
            'tooltip' => [
                'trigger' => 'item',
                'formatter' => '{b}: {c}',
            ],
            'legend' => [],
            'visualMap' => [
                'min' => 0,
                'max' => 10,
                'text' => ['高', '低'],
                'realtime' => true,
                'calculable' => true,
                'show' => true,
                'inRange' => [
                    'color' => ['#f1f1f1', '#25aed4']
                ],
                'orient' => 'horizontal',
                'bottom' => '1%',
                'left' => '0',
                'itemWidth' => '12px',
                'itemHeight' => '200px'
            ],
        ]);
    }

    /**
     * 添加数据
     * @param string $name 地区名称
     * @param int|\Closure $value 数值
     * @return $this
     */
    public function data($name, $value)
    {
        if ($value instanceof \Closure) {
            $value = call_user_func($value);
        }
        $this->data[] = ['value' => $value, 'name' => $name];
        return $this;
    }

    public function jsonSerialize()
    {

        $this->echart->series[] = [
            'type' => 'map',
            'map' => 'china',
            'zoom' => 1.1,
            'showLegendSymbol' => false,
            'selectedMode' => 'single',
            'itemStyle' => [
                'normal' => [
                    'areaColor' => '#f1f1f1',
                    'borderColor' => '#fff',
                ],
                'emphasis' => [
                    'areaColor' => '#5CD2B7'
                ]
            ],
            'label' => [
                'show' => true
            ],
            'data' => $this->data,
        ];
       
        return parent::jsonSerialize(); // TODO: Change the autogenerated stub
    }
}